function [Ut, tm2]= BGCM_simple(ensemble, C, S, alpha, epsilon, iternum)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Implementation of BGCM
% @ Ayan Acharya, Date: 3.4.2011
% ensemble: results with clustering and classification ensemble 
% A: N*v
% Y: v*C
% S: number of supervised models
% N: number of data points
% C: number of classes
% v: number of groups (supervised and unsupervised)
% epsilon: precision parameter
% alpha: weight of the second term in BGCM algorithm
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

[N,M] = size(ensemble);
A     = [];
Y     = [];

for m=1:M
    
    rslt      = ensemble(:,m);
    clsno     = size(unique(ensemble(:,m)),1);
    temp1     = zeros(N,clsno);
    
    for j=1:clsno
        temp2 = find(rslt==j);
        temp1(temp2',j)=1;
    end
    
    A      = [A temp1];
    
    
    temp3  = zeros(clsno,C);
    if(m<=S)
        for j=1:clsno
            k  = find([1:C]==j);
            temp3(j,k)=1;
        end
    end
    Y      = [Y; temp3];
    
end

Ut     = ones(N,C)/C;
Ut_1   = Ut;
Dv     = diag(sum(A,1));
Dn     = diag(sum(A,2));
Kv     = diag(sum(Y,2));
precsn = 1000000;

iter=0;
%while(precsn>epsilon)
tm1 = cputime;

while(iter<iternum)
    
    Qt     = (inv(Dv+alpha*Kv))*(A'*Ut_1+alpha*Kv*Y);
    Ut     = (inv(Dn))*A*Qt;
    precsn = norm(Ut-Ut_1,1);
    Ut_1   = Ut;
    iter=iter+1;
    
end
tm2 = cputime-tm1;


end